
package com.example.cia.mysql.dao.impl;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.example.cia.mysql.dao.IMysqlDao;

public class mysqlDaoImpl implements IMysqlDao<String>{

	@Override
	public List<String> query() throws ClassNotFoundException, SQLException, IOException {
		return null;
	}

	@Override
	public boolean add() {
		return false;
	}

	@Override
	public boolean delete() {
		return false;
	}

	@Override
	public String getTableName() {
		return "tableName";
	}

	@Override
	public String getQulifiedTableName() {
		return "`"+getTableName()+"`";
	}

	@Override
	public String getPrimaryKey() {
		return getTableName()+"_id";
	}

	@Override
	public String getQueryFieldString(int which) {
		return "*";
	}

	@Override
	public List<Integer> queryId() throws ClassNotFoundException, SQLException, IOException {
		List<Integer> l = new ArrayList<Integer>();
		String sql = "SELECT "+getPrimaryKey()+" FROM "+getQulifiedTableName();
		Connection con = new databaseConnectionImpl().getCon();
		PreparedStatement ps = con.prepareStatement(sql);
		ResultSet rs = ps.executeQuery();
		while(rs.next()){
			l.add(rs.getInt(getPrimaryKey()));
		}
		ps.close();
		con.close();
		return l;
	}

	@Override
	public String queryForOneObject() throws ClassNotFoundException, SQLException, IOException {
		return null;
	}

}
